package com.sam.gui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.sam.dialog.CustomAlertDialogBuilder;
import com.sam.gui.base.BaseWebActivity;
import com.sam.platmform.unimplements.PlatformBRHelper;
import com.dejian.platform.R;
public class MainHomeWebActivity extends BaseWebActivity {

    @Override
    protected void initView() {
        super.initView();
        header.setTitle("用户端");
        header.setLeftVisibility(View.GONE);
        header.setRightText("退出");
        setContentUrl("index.php?c=user&a=user_home&platform=android&version=");
    }

    @Override
    public void onHeaderRightBtnClick() {
        new CustomAlertDialogBuilder.Builder(MainHomeWebActivity.this)
                .setTitle("系统提示")
                .setMessage("确认退出本系统吗?")
                .setPositiveButton(android.R.string.ok,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface d,int w) {
                                //跳转到登陆页面 结束当前实例
                                MainHomeWebActivity.this.finish();
                                System.exit(0);
                            }
                        })
                .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d,int w) {

                    }
                }).create().show();
    }

//    @JavascriptInterface
//    public void setting(){  //系统设置
//        Intent intent = new Intent(this, SystemSettingsActivity.class);
//        startActivity(intent);
//    }


    @JavascriptInterface
    public void cf(){  //处方
        Intent intent = new Intent(this, MyPrescriptionWebActivity.class);
        startActivity(intent);
    }

    @JavascriptInterface
    public void bl(){  //病例
        Intent intent = new Intent(this, CaseOfMineWebActivity.class);
        startActivity(intent);
    }

    @JavascriptInterface
    public void myinfo(){  //
        Intent intent = new Intent(this, UserInfoCenterWebActivity.class);
        startActivity(intent);
    }

    @JavascriptInterface
    public void wz(){  //问诊
        Intent intent = new Intent(this, AppointmentAcitivity.class);
        startActivity(intent);
    }

    @JavascriptInterface
    public void jkjc(){  //健康监测
        PlatformBRHelper.getInstance().sendEnterBLEBR(this);
    }

    /**
     * 连续按两次返回键就退出
     */
    private long firstTime;
    private void exitApp(){
        if (System.currentTimeMillis() - firstTime < 3000) {
            finish();
        } else {
            firstTime = System.currentTimeMillis();
            Toast.makeText(this,R.string.press_again_backrun,Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onBackPressed() {
				exitApp();
    }
}
